using System;
using System.Collections.Generic;
using Me.Prettyprint.Cassandra.Model;
using Me.Prettyprint.Cassandra.Model.Thrift;
using Me.Prettyprint.Cassandra.Serializers;
using Me.Prettyprint.Cassandra.Service;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api;
using Me.Prettyprint.Hector.Api.Beans;
using Me.Prettyprint.Hector.Api.Factory;
using Me.Prettyprint.Hector.Api.Mutation;
using Me.Prettyprint.Hector.Api.Query;
using Org.Apache.Cassandra.Thrift;
using Thrift;

namespace Me.Prettyprint.Cassandra.Service.Template
{
    /// <summary>
    /// Predicate wrapping the Thrift IndexClause for the get_indexed_slices call.
    /// </summary>
    /// <typeparam name="K"></typeparam>
    /// <typeparam name="N"></typeparam>
    /// <typeparam name="V"></typeparam>
    public class IndexedSlicesPredicate<K, N, V>
	{
        protected IndexClause indexClause = new IndexClause();

        public IndexedSlicesPredicate(Serializer<K> keySerializer, Serializer<N> nameSerializer, Serializer<V> valueSerializer) : base()
        {
            KeySerializer = keySerializer;
            NameSerializer = nameSerializer;
            ValueSerializer = valueSerializer;
        }
        public IndexedSlicesPredicate<K, N, V> Count(int count)
        {
            indexClause.Count = count;
            return this;
        }
        public IndexedSlicesPredicate<K, N, V> StartKey(K key)
        {
            indexClause.Start_key = KeySerializer.ToBytes(key);
            return this;
        }
        public IndexedSlicesPredicate<K, N, V> AddExpression(N columnName, IndexOperator op, V value)
        {
            indexClause.Expressions.Add(new IndexExpression(NameSerializer.ToBytes(columnName), op, ValueSerializer.ToBytes(value)));
            return this;
        }
        public IndexClause ToThrift()
        {
            if (!indexClause.__isset.start_key)
            {
                indexClause.Start_key = new byte[0];
            }
            return indexClause;
        }
        protected Serializer<K> KeySerializer
        {
            get;
            set;
        }
        protected Serializer<N> NameSerializer
        {
            get;
            set;
        }
        protected Serializer<V> ValueSerializer
        {
            get;
            set;
        }
	}
}